<?php

$mid 	= ( ( true == isset( $_GET['mid'] ) && true == valStr( $_GET['mid'] ) ) ? $_GET['mid'] : NULL );
$smid 	= ( ( true == isset( $_GET['smid'] ) && true == valStr( $_GET['smid'] ) ) ? $_GET['smid'] : NULL );

require_once 'classes/CasePapers.class.php';
require_once 'classes/Patients.class.php';
require_once 'classes/ChargeTypes.class.php';
require_once 'classes/Diagnosises.class.php';

$objCasePapers 		= new CasePapers();
$arrobjCasePapers 	= $objCasePapers->fetchAllCasePapers();

$objPatient 	= new Patients();
$objChargeType 	= new ChargeTypes();
$objDiagnosis 	= new Diagnosises();

$arrobjPatients = $objPatient->fetchAllPatients();
$arrobjPatients = rekeyObjects( 'Id', $arrobjPatients );

$arrobjChargeTypes = $objChargeType->fetchAllChargeTypes();
$arrobjChargeTypes = rekeyObjects( 'Id', $arrobjChargeTypes );

$arrobjDianosises = $objDiagnosis->fetchAllDiagnosises();
$arrobjDianosises = rekeyObjects( 'Id', $arrobjDianosises );

if( false == valArr( $arrobjCasePapers ) ) {
	echo '<h2>Casepapers are not avaliable.</h2>';
} else {
?>
<html>
<head>
<link href="css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
<script src="js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="js/bootstrap-confirmation.js" type="text/javascript"></script>
<script>
	$(document).ready(function() {
		$('#dataTables-example').dataTable();
	});
</script>
<script>
function DeleteData(id){
               var r = confirm("Are You Sure Delete This Case Paper?");
               if (r==true){
                  $.ajax({
                     type: "POST",
                     url: "modules.php?file=delete_case_papers",
                     data:{did:id},
                     beforeSend : function () {
                     },
                     success:function(){
					 location.reload();
                     }
                  });
               }else{   
               }
            }
</script>
<style>
	.thclass{
	font-size:12px;
	}
	.tbclass{
	font-size:12px;
	}
</style>
</head>
<body>
<div style="margin-left:12px; margin-top: 10px;">
<p>
	<a class="btn btn-outline btn-primary btn-xs" id="active" href="modules.php?file=case_papers&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >Create Case Paper</a>&nbsp;
</p> 
</div>

<div class="col-lg-12">
	<div class="panel panel-primary">
		
		<div class="panel-heading"><i class="fa fa-bell fa-fw"></i>Patient's List</div>
		<div class="panel-body">
			<div class="table-responsive">
				<table class="table table-striped table-bordered table-hover" id="dataTables-example">
					<thead class="thclass">
						<tr>
							<th>Sr.No</th>
							<th>Casepaper Id</th>
							<th>Patient Details</th>
							<th>Diagnosis Details</th>
							<th>Charge Type</th>
							<th>Submitted Date</th>
							<th style="width: 60px;">Amount Applied</th>
							<th style="width: 120px;">Accsess Control</th>
					</thead>
					<tbody class="tbclass">
					<?php 
					$intSnCount = 1;
					foreach( $arrobjCasePapers as $objCasePaper ) {
							$n++;
							
							$objPatient = getArrayElementByKey( $objCasePaper->getPatientId(), $arrobjPatients );
							$objChargeType 	= getArrayElementByKey( $objCasePaper->getChargeTypeId(), $arrobjChargeTypes );
							$objDiagnosis 	= getArrayElementByKey( $objCasePaper->getDiagnosisId(), $arrobjDianosises );
							
							if( false == valObj( $objPatient, 'BasePatients' ) ) continue;
							
							// Date Format
							//http://www.php.net//manual/en/datetime.formats.date.php
					?>
							<tr class="odd gradeX">
							<td><?  echo $intSnCount; ?></td>
							<td><? echo $objCasePaper->getId(); ?></td>
							<td><? echo ( true == valObj( $objPatient, 'BasePatients' ) ) ? $objPatient->getFirstName() . ' ' . $objPatient->getLastName() . ' <b>(' . $objCasePaper->getPatientId() . ')</b>' : $objCasePaper->getPatientId(); ?></td>
							<td><? echo ( true == valObj( $objDiagnosis, 'BaseDiagnosises' ) ) ? $objDiagnosis->getName() . ' <b>('. $objDiagnosis->getId() . ')</b>' : $objCasePaper->getDiagnosisId(); ?></td>
							<td><? echo ( true == valObj( $objChargeType, 'BaseChargeTypes' ) ) ? $objChargeType->getName() . ' <b>(' . $objChargeType->getId() . ')</b>' :$objCasePaper->getChargeTypeId(); ?></td>
							<td><? echo date( 'd-M-Y h:i:a', strtotime( $objCasePaper->getUpdatedOn() ) ); ?></td>
							<td><? echo $objCasePaper->getAmountPaid(); ?></td>
							<td>
								<a href="modules.php?file=case_papers&patient_id=<? echo $objCasePaper->getPatientId(); ?>&case_paper_id=<? echo $objCasePaper->getId(); ?>&mid=<? echo $mid;?>&smid=<? echo $smid;?>" title="Update patient information"><img src="images/icons/update.png" width="25" height="25"></a>
								&nbsp;&nbsp;&nbsp;
								<a id="delete_casepaper" onClick="DeleteData(<?echo $objCasePaper->getId();?>);"><img src="images/icons/delete.jpg" width="25" height="25"></a>
								&nbsp;&nbsp;&nbsp;
								<a href="modules.php?file=print_case_paper&type=print&patient_id=<?echo $objPatient->getId();?>&case_paper_id=<?echo $objCasePaper->getId();?>&mid=<? echo $mid; ?>&smid=<? echo $smid;?>" title="delete_diagnosis_type"><img src="images/icons/print_printer.png" width="30" height="30"></a>
							</td>
							</tr>
					<?
					} 
					?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
</body>
</html>
<?php
}
?>